package com.llkj.contractmanagement.contractmanagement.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;


import com.llkj.contractmanagement.R;
import com.llkj.contractmanagement.customview.RoundImageView;
import com.llkj.contractmanagement.model.CollectionBean;
import com.llkj.contractmanagement.utils.ImageLoaderUtil;

import java.util.List;

/**
 * Created by dong.yj on 2016/5/5.
 * <p/>
 * 我的收藏
 */
public class CollectionDeleteAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<CollectionBean.YrlistBean> collectionBeanList;

    public List<CollectionBean.YrlistBean> getContactList() {
        return collectionBeanList;
    }

    public void setContactList(List<CollectionBean.YrlistBean> collectionBeanList) {
        this.collectionBeanList = collectionBeanList;
    }


    public CollectionDeleteAdapter(Context context, List<CollectionBean.YrlistBean> collectionBeanList) {
        this.context = context;
        this.collectionBeanList = collectionBeanList;
        this.inflater = inflater.from(context);
    }

    @Override
    public int getCount() {
        return collectionBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return collectionBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.lv_collection_delete_item, null);
            viewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.check_choose_delete);
            viewHolder.tv_contactName = (TextView) convertView.findViewById(R.id.tv_actor_name);
            viewHolder.tv_contactPhone = (TextView) convertView.findViewById(R.id.tv_actor_part);
            viewHolder.riv_head_pic = (RoundImageView) convertView.findViewById(R.id.riv_head_actor);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
//        viewHolder.checkBox.setTag(position);
        CollectionBean.YrlistBean yrlistBean = collectionBeanList.get(position);
        viewHolder.checkBox.setChecked(yrlistBean.isFalg());
        viewHolder.tv_contactName.setText(yrlistBean.getName());
        viewHolder.tv_contactPhone.setText(yrlistBean.getPart());
        ImageLoaderUtil.displayHeaderImage(yrlistBean.getLogo(), viewHolder.riv_head_pic);
        return convertView;
    }

    public static class ViewHolder {
        TextView tv_contactName;
        TextView tv_contactPhone;
        public CheckBox checkBox;
        RoundImageView riv_head_pic;
    }
}
